<?php

namespace app\modules\info\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\info\models\info;

/**
 * infoSearch represents the model behind the search form about `app\modules\info\models\info`.
 */
class infoSearch extends info
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['info_id', 'userid', 'views', 'rating', 'show_order', 'info_p_id'], 'integer'],
            [['info_title', 'info_author', 'info_from', 'info_url', 'info_thumb', 'info_tag', 'info_summary', 'info_content', 'info_category', 'info_status', 'last_viewed', 'date_added', 'active', 'key_words', 'info_org'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = info::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'info_id' => $this->info_id,
            'last_viewed' => $this->last_viewed,
            'date_added' => $this->date_added,
            'userid' => $this->userid,
            'views' => $this->views,
            'rating' => $this->rating,
            'show_order' => $this->show_order,
            'info_p_id' => $this->info_p_id,
        ]);

        $query->andFilterWhere(['like', 'info_title', $this->info_title])
            ->andFilterWhere(['like', 'info_author', $this->info_author])
            ->andFilterWhere(['like', 'info_from', $this->info_from])
            ->andFilterWhere(['like', 'info_url', $this->info_url])
            ->andFilterWhere(['like', 'info_thumb', $this->info_thumb])
            ->andFilterWhere(['like', 'info_tag', $this->info_tag])
            ->andFilterWhere(['like', 'info_summary', $this->info_summary])
            ->andFilterWhere(['like', 'info_content', $this->info_content])
            ->andFilterWhere(['like', 'info_category', $this->info_category])
            ->andFilterWhere(['like', 'info_status', $this->info_status])
            ->andFilterWhere(['like', 'active', $this->active])
            ->andFilterWhere(['like', 'key_words', $this->key_words])
            ->andFilterWhere(['like', 'info_org', $this->info_org]);

        return $dataProvider;
    }
}
